{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "x6GyniNay_k8"
      },
      "outputs": [],
      "source": [
        "# Создание базы данных\n",
        "import sqlite3\n",
        "\n",
        "def init_db():\n",
        "    conn = sqlite3.connect('hospital_schedule.db')\n",
        "    c = conn.cursor()\n",
        "    c.execute('''\n",
        "        CREATE TABLE IF NOT EXISTS doctors (\n",
        "            id INTEGER PRIMARY KEY,\n",
        "            name TEXT NOT NULL,\n",
        "            skills TEXT NOT NULL\n",
        "        )\n",
        "    ''')\n",
        "    c.execute('''\n",
        "        CREATE TABLE IF NOT EXISTS schedules (\n",
        "            doctor_id INTEGER,\n",
        "            day TEXT,\n",
        "            time TEXT,\n",
        "            FOREIGN KEY (doctor_id) REFERENCES doctors (id)\n",
        "        )\n",
        "    ''')\n",
        "    c.execute('''\n",
        "        CREATE TABLE IF NOT EXISTS requests (\n",
        "            id INTEGER PRIMARY KEY AUTOINCREMENT,\n",
        "            doctor_id INTEGER,\n",
        "            request_type TEXT,\n",
        "            status TEXT,\n",
        "            FOREIGN KEY (doctor_id) REFERENCES doctors (id)\n",
        "        )\n",
        "    ''')\n",
        "    conn.commit()\n",
        "    conn.close()\n",
        "\n",
        "init_db()\n",
        "\n",
        "\n",
        "\n",
        "# Создание Flask-приложения\n",
        "from flask import Flask, request, jsonify, render_template\n",
        "import sqlite3\n",
        "\n",
        "app = Flask(__name__)\n",
        "\n",
        "# Helper functions\n",
        "def query_db(query, args=(), one=False):\n",
        "    conn = sqlite3.connect('hospital_schedule.db')\n",
        "    cur = conn.cursor()\n",
        "    cur.execute(query, args)\n",
        "    rv = cur.fetchall()\n",
        "    conn.close()\n",
        "    return (rv[0] if rv else None) if one else rv\n",
        "\n",
        "def execute_db(query, args=()):\n",
        "    conn = sqlite3.connect('hospital_schedule.db')\n",
        "    cur = conn.cursor()\n",
        "    cur.execute(query, args)\n",
        "    conn.commit()\n",
        "    conn.close()\n"
      ]
    }
  ]
}